<?php
/*namespace app\index\model;
use app\common\model\Base;
use think\Db;

class KjjgList extends Base
{
    //近期开奖列表
	public function getRunLotteryRecent() {
	    $res = KjjgList::name('kjjg_list')->alias('kl')
	                ->join('__CAIPAI_LIST__ cl','kl.czid=cl.id')
	                ->field('kl.*,cl.cp_name_new,cl.cp_name_old,cl.initial_class_id')
	                ->where('kl.kjjg','>',0)
	                ->where('cl.cp_if_open',1)
	                ->order('id','DESC')
	                ->limit(5)
	                ->select()->toArray();
	    return $res;
	}
	
	//最新开奖结果
	public function getRunLotteryResult($czid) {
	    if(!$czid) return array();
	    $res = KjjgList::name('kjjg_list')->where('czid',$czid)->where('kjjg','>',0)->order('jztime','DESC')->find()->toArray();
	    $initial_class_id = Db::name('caipai_list')->where('id',$czid)->value('initial_class_id');
	    $res['initial_class_id'] = $initial_class_id;
	    return $res;
	}*/

namespace app\index\model;
use app\common\model\Base;
use think\Db;

class KjjgList extends Base
{
	//近期开奖列表
	public function getRunLotteryRecent() {
		return KjjgList::name('kjjg_list')->alias('kl')
			->join('__CAIPAI_LIST__ cl', 'kl.czid=cl.id')
			->field('kl.*,cl.cp_name_new,cl.cp_name_old,cl.initial_class_id')
			->where('kl.kjjg', '>', 0)
			->where('cl.cp_if_open', 1)
			->order('id', 'DESC')
			->limit(5)
			->select()->toArray();
	}

	//最新开奖结果
	static function getRunLotteryResult($czid) {
		if(!$czid) return [];
		return Db::name('kjjg_list kl')
			->join('caipai_list cl','cl.id = kl.czid')
			->field('kl.*, cl.initial_class_id')
			->where('czid',$czid)
			->where('kjjg','>',0)
			->order('jztime','DESC')
			->find();
	}
	
	//单独彩种所有开奖结果
    public function getLotteryNotices($czid) {
        if(!$czid) return array();
        $res = KjjgList::name('kjjg_list')->alias('kl')
                    ->join('__CAIPAI_LIST__ cl','kl.czid=cl.id')
                    ->field('kl.*,cl.cp_name_new,cl.cp_name_old,cl.initial_class_id')
                    ->where("kl.kjjg>0 AND kl.czid={$czid} ")
                    ->order('jztime','DESC')
                    ->limit(50)
                    ->select()->toArray();
        return $res;
    }
    
    //单独彩种某期开奖结果
    public function getLotteryNotice($czid,$sql_shert) {
        if(!$czid || !$sql_shert) return array();
        $res = KjjgList::name('kjjg_list')->alias('kl')
                    ->join('__CAIPAI_LIST__ cl','kl.czid=cl.id')
                    ->field('kl.*,cl.cp_name_new,cl.cp_name_old,cl.initial_class_id')
                    ->where("kl.kjjg>0 AND kl.czid={$czid} {$sql_shert} ")
                    ->order('jztime','DESC')
                    ->select()->toArray();
        return $res;
    }
    
}
